package com.heer.gymnasium.activity;

import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.heer.api.ResponseData.ApiResponse;
import com.heer.api.callback.BaseCallback;
import com.heer.gymnasium.R;
import com.heer.model.JoinUsBean;

import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Response;

/**
 * Created by heer on 17/4/10.
 */

public class SettledInActivity extends BaseActivity {
    @BindView(R.id.edit_name)
    EditText editName;
    @BindView(R.id.edit_type)
    EditText editType;
    @BindView(R.id.edit_area)
    EditText editArea;
    @BindView(R.id.edit_link)
    EditText editLink;
    @BindView(R.id.edit_phone)
    EditText editPhone;
    @BindView(R.id.btn_submit)
    Button btnSubmit;

    @Override
    protected void init() {
        super.init();
        setContentView(R.layout.activity_settled_in);
    }

    @Override
    protected void initView() {
        super.initView();
        titleBuilder.setTitleText("商家入驻");
    }

    @OnClick(R.id.btn_submit)
    public void onClick() {
        mAppHelper.apiService().joinUs(editName.getText().toString().trim(),
                editType.getText().toString().trim(),
                editArea.getText().toString().trim(),
                editLink.getText().toString().trim(),
                editPhone.getText().toString().trim()).enqueue(new BaseCallback<ApiResponse<JoinUsBean>>() {
            @Override
            public void onResponse(Call<ApiResponse<JoinUsBean>> call, Response<ApiResponse<JoinUsBean>> response) {
                super.onResponse(call, response);
                if (response.isSuccessful() && response.body().isSccessful()) {
                    Toast.makeText(SettledInActivity.this, "提交成功", Toast.LENGTH_SHORT).show();
                    finish();
                }
                if(response.body().isTokenExpire()){
                    toLogin();
                }
            }

            @Override
            public void onFailure(Call<ApiResponse<JoinUsBean>> call, Throwable t) {
                super.onFailure(call, t);
            }
        });
    }
}
